<template>
  <div class="digital-twin">
    <h1>数字孪生驾驶舱</h1>
    
    <div class="kpi-section">
      <h2>实时业务指标</h2>
      <div class="kpi-grid">
        <div class="kpi-card" v-for="kpi in kpis" :key="kpi.label">
          <div class="kpi-label">{{ kpi.label }}</div>
          <div class="kpi-value">{{ kpi.value }}</div>
          <div class="kpi-unit">{{ kpi.unit }}</div>
        </div>
      </div>
    </div>
    
    <div class="simulation-section">
      <h2>What-If 分析</h2>
      <button class="btn-primary" @click="runSimulation">运行业务模拟</button>
      
      <div v-if="simulationResult" class="result-card">
        <h3>模拟结果</h3>
        <div v-for="(value, key) in simulationResult" :key="key" class="metric-row">
          <span class="metric-label">{{ key }}</span>
          <span class="metric-value">{{ value }}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'

const kpis = ref([
  { label: '小时消息量', value: 0, unit: '条' },
  { label: '小时文件', value: 0, unit: '个' },
  { label: '小时通话', value: 0, unit: '分钟' },
  { label: '小时订单', value: 0, unit: '单' }
])

const simulationResult = ref<Record<string, number> | null>(null)

const runSimulation = () => {
  // Mock simulation
  simulationResult.value = {
    '吞吐量': 1200,
    '响应时间': 150,
    '错误率': 0.01
  }
}
</script>

<style scoped>
.digital-twin {
  padding: 20px;
}

h1 {
  font-size: 2rem;
  color: #2c3e50;
  margin-bottom: 30px;
}

h2 {
  font-size: 1.5rem;
  color: #34495e;
  margin-bottom: 20px;
}

.kpi-section {
  margin-bottom: 40px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
}

.kpi-card {
  background: white;
  padding: 30px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  text-align: center;
}

.kpi-label {
  font-size: 0.9rem;
  color: #7f8c8d;
  margin-bottom: 10px;
}

.kpi-value {
  font-size: 2.5rem;
  font-weight: bold;
  color: #667eea;
  margin-bottom: 5px;
}

.kpi-unit {
  font-size: 0.8rem;
  color: #95a5a6;
}

.simulation-section {
  background: white;
  padding: 30px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.btn-primary {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 12px 30px;
  border: none;
  border-radius: 6px;
  font-size: 1rem;
  cursor: pointer;
  margin-bottom: 20px;
}

.btn-primary:hover {
  opacity: 0.9;
}

.result-card {
  background: #f8f9fa;
  padding: 20px;
  border-radius: 6px;
  margin-top: 20px;
}

.metric-row {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid #e9ecef;
}

.metric-row:last-child {
  border-bottom: none;
}

.metric-label {
  color: #495057;
}

.metric-value {
  font-weight: bold;
  color: #212529;
}
</style>
